#include "solar/trunk/NReaptFruit.h"

MessageFruitBox::MessageFruitBox(QWidget *parent)
    {
        setParent(parent);

        NW_Download->doconfigur_imgsetting(NT::DRAWTYPE_RECT, NT::PIXLOAD_IGNORERATIO_LOWER, 4, QPoint(2,0));
        NW_Download->doconfigur_text("下载资源");
        NW_Download->doconfigur_textsetting(QFont("Kaiti", 13), QPoint(5,0));
        NW_Download->doconfigur_brighttype(NT::DRAWTYPE_RECT);
        NW_Download->doconfigur_pixmapgroup({{MSEVKEY.WIN_NORMAL, ":/PIXMAP/bench/nw_download-dark.png"},
                                             {MSEVKEY.WIN_ENTER, ":/PIXMAP/bench/nw_download-shallow.png"}});
        NW_Download->doconfigur_colorgroup({{MSEVKEY.WIN_NORMAL, QColor(116,124,141)},
                                            {MSEVKEY.WIN_ENTER, QColor(234,237,241)}});
        NW_Download->doconfigur_backcolorgroup({{MSEVKEY.WIN_NORMAL, QColor(234,237,241)},
                                                {MSEVKEY.WIN_ENTER, QColor(95,136,105)}});
        NW_Download->doconfigur_bordercolorgroup({{MSEVKEY.WIN_NORMAL, QColor(222,225,232)},
                                                  {MSEVKEY.WIN_ENTER, QColor(191,196,210)}});


        NW_Comeback->doconfigur_pixmapgroup({{MSEVKEY.WIN_NORMAL, ":/PIXMAP/bench/nw-comeback-dark.png"},
                                             {MSEVKEY.WIN_ENTER, ":/PIXMAP/bench/nw-comeback-shallow.png"}});
        NW_Comeback->doconfigur_imgsetting(NT::DRAWTYPE_RECT, NT::PIXLOAD_IGNORERATIO_LOWER);
        NW_Comeback->doconfigur_brighttype(NT::DRAWTYPE_ROUND);

        NW_Trylsten->doconfigur_imgsetting(NT::DRAWTYPE_RECT, NT::PIXLOAD_IGNORERATIO_LOWER, 4, QPoint(2,0));
        NW_Trylsten->doconfigur_text("试听媒体");
        NW_Trylsten->doconfigur_textsetting(QFont("Kaiti", 13), QPoint(5,0));
        NW_Trylsten->doconfigur_brighttype(NT::DRAWTYPE_RECT);
        NW_Trylsten->doconfigur_pixmapgroup({{MSEVKEY.WIN_NORMAL, ":/PIXMAP/bench/nw-trylisten-dark.png"},
                                             {MSEVKEY.WIN_ENTER, ":/PIXMAP/bench/nw-trylisten-shallow.png"}});
        NW_Trylsten->doconfigur_colorgroup({{MSEVKEY.WIN_NORMAL, QColor(116,124,141)},
                                            {MSEVKEY.WIN_ENTER, QColor(234,237,241)}});
        NW_Trylsten->doconfigur_backcolorgroup({{MSEVKEY.WIN_NORMAL, QColor(234,237,241)},
                                                {MSEVKEY.WIN_ENTER, QColor(95,136,105)}});
        NW_Trylsten->doconfigur_bordercolorgroup({{MSEVKEY.WIN_NORMAL, QColor(222,225,232)},
                                                  {MSEVKEY.WIN_ENTER, QColor(191,196,210)}});

        NW_Download->setFixedHeight(32);
        NW_Comeback->setFixedSize(32,32);
        NW_Trylsten->setFixedHeight(32);

        roof_win->doconfigur_secolor({QColor(232,237,239), QColor(242,241,247), QColor(232,237,238)});

        NW_mediaTabWidget->setFont(globalFont);
        NW_mediaTabWidget->setSelectionMode(QAbstractItemView::SingleSelection);
        NW_mediaTabWidget->setContentsMargins(0, 0, 0, 0);
        NW_mediaTabWidget->horizontalHeader()->setVisible(false);
        NW_mediaTabWidget->horizontalHeader()->sectionResizeMode(QHeaderView::Stretch);
        NW_mediaTabWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
        NW_mediaTabWidget->setEditTriggers(QAbstractItemView::EditTrigger::NoEditTriggers);
        NW_mediaTabWidget->verticalHeader()->setVisible(false);
        NW_mediaTabWidget->setShowGrid(false);
        NW_mediaTabWidget->setColumnCount(3);
        NW_mediaTabWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        NW_mediaTabWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        NW_mediaTabWidget->setScrollBarWidth(Qt::Vertical, 22);

        roof_hbox->addWidget(NW_Download);
        roof_hbox->addWidget(NW_Comeback, 0, Qt::AlignCenter);
        roof_hbox->addWidget(NW_Trylsten);
        roof_hbox->setSpacing(30);

        global_vbox->addWidget(roof_win);
        global_vbox->addWidget(NW_mediaTabWidget);
        global_vbox->setSpacing(10);
        setCentralWidget(global_pwidget);

        connect(NW_Download, &NinsipidView::msev_pre, this, &MessageFruitBox::msev_dlcl);
        connect(NW_Trylsten, &NinsipidView::msev_pre, this, &MessageFruitBox::msev_trcl);
        connect(NW_Comeback, &NinsipidView::msev_pre, this, &MessageFruitBox::msev_back);
}


void MessageFruitBox::resizeEvent(QResizeEvent *event){

    QWidget::resizeEvent(event);
}


void MessageFruitBox::nw_viewlayout_init(int row, QString name, QString artist, QString album, QPixmap cover){
    QString nametstring = name + "\n\n" + artist + " # " + album + " media/suffix";
    Nwidget *mdrs_cover = new Nwidget();
    mdrs_cover->setFixedSize(80,80);
    mdrs_cover->doconfigur_pixmap(cover, QSize(66, 66), false, 6);
    QString objname = QString::number(row + 1);
    QTableWidgetItem *item_bsifdesc = new QTableWidgetItem(objname);
    QTableWidgetItem *item_bsifcover = new QTableWidgetItem();
    QTableWidgetItem *item_bsifnairt = new QTableWidgetItem(nametstring);

    item_bsifdesc->setTextAlignment(Qt::AlignCenter);
    item_bsifcover->setTextAlignment(Qt::AlignCenter);
    item_bsifnairt->setTextAlignment(Qt::AlignBaseline);

    NW_mediaTabWidget->setItem(row, 0, item_bsifdesc);
    NW_mediaTabWidget->setItem(row, 1, item_bsifcover);
    NW_mediaTabWidget->setCellWidget(row, 1, mdrs_cover);
    NW_mediaTabWidget->setItem(row, 2, item_bsifnairt);

    if (!impact_swtc["tab-column-specing-adjusted"])
    {
        int first_width = NW_mediaTabWidget->columnWidth(0);
        int second_width = NW_mediaTabWidget->columnWidth(1);
        NW_mediaTabWidget->setColumnWidth(2,
                                          NW_mediaTabWidget->width() -
                                          first_width -
                                          second_width);
        impact_swtc["tab-column-specing-adjusted"] = true;
    }
}


void MessageFruitBox::paintEvent(QPaintEvent *event){
    QWidget::paintEvent(event);
    QPainter captainPainter(this);
    captainPainter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
    QPainterPath path;
    path.addRoundedRect(rect().adjusted(0, -win_radius, 0, 0), win_radius, win_radius);
    captainPainter.setClipPath(path);
    captainPainter.setPen(QPen(Qt::transparent));
    QRect realrect = captainPainter.viewport();
    Extend::painterLinear(captainPainter, realrect, NT::ORIEN_HORIZONTAL, {QColor(247,208,235), QColor(237,238,243), QColor(247,208,235)});
}


MessageFruitBox::~MessageFruitBox(){
    delete NW_Download;
    delete NW_Trylsten;
    delete NW_mediaTabWidget;
    delete global_pwidget;
}
